package ldkxingzhe.ldkxingzhedemo.tab;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.amap.api.maps.offlinemap.OfflineMapCity;

import java.util.ArrayList;
import java.util.List;

import ldkxingzhe.ldkxingzhedemo.R;


/**
 * Created by liangdengke on 2015/9/1.
 */
public class OfflineMapDownloadManagerFragment extends Fragment{

    private final String TAG = OfflineMapDownloadManagerFragment.class.getSimpleName();
    private CityListFragment mCityListFragment;
    private Activity context;
    private ListView mListView;
    private List<OfflineMapCity> result = new ArrayList<>();
    CityListAdapter mAdapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        context = getActivity();
        mCityListFragment = (CityListFragment)((OffLineMapActivity)context).fragments[1];

        View view = context.getLayoutInflater().inflate(R.layout.fragment_down_manager,container,false);
        mListView = (ListView)view.findViewById(R.id.list_view);
        mAdapter = new CityListAdapter(mCityListFragment,result);
        mListView.setAdapter(mAdapter);
        mListView.setEmptyView(view.findViewById(android.R.id.empty));
        return view;
    }

    public void updateResult(List<OfflineMapCity> result){
        this.result.clear();
        this.result.addAll(result);
        Log.d(TAG,"updateResult, result.size = " + result.size());
        if(mAdapter != null){
            mAdapter.notifyDataSetChanged();
        }
    }
}
